package com.xyh.concurrency.example.singleton;

import lombok.extern.slf4j.Slf4j;

@Slf4j
/**
 *  使用枚举创建工厂对象
 */
public class SingletonExample2 {
    private SingletonExample2() {
    }

    public static SingletonExample2 getInstance() {
        return Singleton.INSTANCE.getInstance();
    }

    /**
     * chuangjian
     */
    private enum Singleton {
        INSTANCE;
        private SingletonExample2 singletonExample2;

        /**
         * jvm保证这个方法直至之
         */

        Singleton() {
            singletonExample2 = new SingletonExample2();
        }

        public SingletonExample2 getInstance() {
            return singletonExample2;
        }

    }

}
